package com.oa.admin.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.admin.entity.Holiday;
import com.oa.admin.service.IHolidayService;
import com.oa.admin.vo.UserHolidayListVO;
import com.oa.core.BaseController;
import com.oa.core.utils.DateUtils;
import com.oa.pm.entity.EntryInformation;
import com.oa.pm.service.IEntryInformationService;
import com.oa.system.entity.User;
import com.oa.system.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(description = "假期设置")
@RequestMapping("/holiday")
@RestController
public class HolidayController extends BaseController {


    @Autowired
    private IHolidayService holidayService;

    @Autowired
    private IUserService userService;

    @Autowired
    private IEntryInformationService entryInformationService;

    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public Resp<Page<Holiday>> list(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam Integer type){
        Page page = new Page(pageNum, pageSize);
        Wrapper wrapper = new EntityWrapper();
        if(type <= 2){
            wrapper.eq("holiday_type", type);
        }
        return new Resp().success(holidayService.selectPage(page, wrapper));
    }

    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    @GetMapping("/{id}")
    public Resp<Page<Holiday>> findById(@PathVariable String id){
        return new Resp().success(holidayService.selectById(id));
    }


    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    @PostMapping("")
    public Resp add(@ApiParam(value = "假期") @RequestBody(required = false) Holiday holiday) {
        if (holidayService.insert(holiday)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    @CommonController
    @Description("修改")
    @ApiOperation(value = "修改")
    @PutMapping("")
    public Resp put(@ApiParam(value = "假期") @RequestBody(required = false) Holiday holiday) {
        if (holidayService.updateById(holiday)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    @CommonController
    @Description("修改")
    @ApiOperation(value = "修改")
    @PutMapping("/user")
    public Resp putUser() {
        return holidayService.updateUser();
    }

    @CommonController
    @Description("删除")
    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Resp delete(@ApiParam(value = "假期") @PathVariable Long id) {
        if (holidayService.deleteById(id)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }
}
